package com.bosicen.crm.service.sysmanage;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;

import com.bosicen.crm.dao.entity.Function;
import com.bosicen.crm.dao.entity.UserFunction;
import com.bosicen.crm.dao.sysmanage.FunctionRoleDao;
import com.bosicen.crm.tools.AppUtil;

import org.springframework.transaction.annotation.Transactional;
/**
 * 功能
 * @author tigerlei
 *
 */
@Service("functionService")
public class FunctionServiceImpl {
	@Autowired
	private FunctionRoleDao functionRoleDao;

	// @Transactional(readOnly = false,propagation=Propagation.REQUIRED,
	// rollbackFor=Exception.class)

	/****
	 * 查询列表
	 * 
	 * @param companyid
	 * @return
	 */
	public List<Function> findFunctionList(int id) {
		List<Function> list = null;
		try {
			list = this.functionRoleDao.findFunctionList(id);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return list;
	}

	/***
	 * 新增/修改
	 * 
	 * @param p
	 */
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public boolean saveOrUpdateFunction(Function p) {
		boolean b = false;
		try {
			 this.functionRoleDao.saveOrUpdate(p);

		} catch (Exception ex) {
			ex.printStackTrace();
			return b;
		}
		return true;
	}

	/****
	 * 按ID查询
	 * 
	 * @param companyid
	 * @return
	 */
	public Function findFunctionById(int id) {
		Function function = null;
		try {
			function = this.functionRoleDao.findFunctionById(id);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return function;
	}

	/****
	 * 删除 
	 * 
	 * @param p
	 */
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public boolean delFunction(Function p) {
		try {
			this.functionRoleDao.delete(p);
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
		return true;
	}
	
	/**
	 * 保存用户功能
	 * @param functionIds
	 * @param userid
	 * @return
	 */
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public boolean saveUserFunction(String functionIds,int userid){
		return this.functionRoleDao.saveUserFunction(functionIds, userid);
	}
	
	/**
	 * 查询用户功能
	 * @param id
	 * @return
	 */
	public List<UserFunction> findUserFunctionById(int userid){
		return this.functionRoleDao.findUserFunctionById(userid);
	}
	

}
